Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Random -function, timer method
- //
- //Timer_A is setup in capture mode. SMCLK is set to the
- //DCO and set as the input clock to Timer_A. ACLK
- //is set to the VLO, which is the trigger for the capture.
- //Timer_A counts the number of DCO clock pulses
- //before the next VLO low-to-high transition occurs.
- //The number of DCO clock pulses is saved by the timer
- //in a Capture/Compare Register (CCR).
- int randomize_led(){
- while(1){
- BCSCTL2 &= ~(DIVS1 + DIVS0); // SMCLK / 1 (subsystem clock)
- TACCR0 = 0;
- TACCTL0 = CAP | CM_1 | CCIS_1; // Capture mode, positive edge/ aclk input
- TACTL = TASSEL_2 | MC_2; // SMCLK, continuous up
- while (!(CCIFG & TACCTL0)); // Wait for interrupt
- TACCTL0 &= ~CCIFG; // Clear interrupt
- result = TACCR0;
- result = result & 0x0007; // bit masking the result to 3 bits
- BCSCTL2 |= DIVS1 + DIVS0; // SMCLK / 8 (subsystem clock)
- // set SMCLK back to 125KHZ
- if(result > 6){
- result = 6;
- }
- if(result < 1){
- result = 1;
- }
- if(result != prev_result){
- prev_result = result;
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement